﻿using System;
using System.Text;

namespace Lawn.AppServer
{
    public class DefaultSerializeProvider:ISerializeProvider
    {
        public T Deserialize<T>(byte[] data) where T:class
        {
            if (typeof(T)==typeof(string))
            {

                return (T)Convert.ChangeType(Encoding.UTF8.GetString(data), typeof(T));

            }
            else
            {
                return default(T);
            }
           
        }

        public byte[] Serialize<T>(T t)
        {
            if (typeof(T) == typeof(string))
            {
                string data = t as string;
                return Encoding.UTF8.GetBytes(data);
            }

            return null;
        }
    }
}